package com.wno704.intf.listener;

import com.wno704.intf.entity.IntfLog;
import com.wno704.intf.event.LogEvent;
import com.wno704.intf.service.IntfLogService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @ClassName IntfLogListener
 * @Description TODO
 * @Author wno704
 * @Date 2023/10/24 10:38
 * @Version 1.0
 */
@Async
@Slf4j
@Component
public class IntfLogListener {

    @Autowired
    IntfLogService intfLogService;

    @SneakyThrows
    @EventListener(LogEvent.class)
    public void saveIntfLog(LogEvent event) {
        IntfLog intfLog = event.getIntfLog();
        int type = event.getType();
        if(type==0){
            intfLogService.insertLog(intfLog);
        }else if(type==1){
            intfLogService.updateLog(intfLog);
        }
    }
}
